home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / windows / ocx / ipack.exe / MAILV.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-07-16  |  28.9 KB  |  889 lines

  1. VERSION 4.00
  2. Begin VB.Form MailForm 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Mabry Mail"
  6.    ClientHeight    =   6945
  7.    ClientLeft      =   1290
  8.    ClientTop       =   3075
  9.    ClientWidth     =   9705
  10.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   9.75
  13.       Charset         =   0
  14.       Weight          =   400
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   7635
  21.    Left            =   1230
  22.    LinkTopic       =   "Form1"
  23.    ScaleHeight     =   6945
  24.    ScaleWidth      =   9705
  25.    Top             =   2445
  26.    Width           =   9825
  27.    Begin VB.Timer Timer1 
  28.       Enabled         =   0   'False
  29.       Interval        =   1
  30.       Left            =   5160
  31.       Top             =   1200
  32.    End
  33.    Begin VB.CheckBox chkHostDelete 
  34.       Caption         =   "Host &Delete"
  35.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  36.          Name            =   "MS Sans Serif"
  37.          Size            =   8.25
  38.          Charset         =   0
  39.          Weight          =   400
  40.          Underline       =   0   'False
  41.          Italic          =   0   'False
  42.          Strikethrough   =   0   'False
  43.       EndProperty
  44.       Height          =   255
  45.       Left            =   6840
  46.       TabIndex        =   5
  47.       Top             =   120
  48.       Width           =   1215
  49.    End
  50.    Begin VB.TextBox textBody 
  51.       Appearance      =   0  'Flat
  52.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  53.          Name            =   "Courier New"
  54.          Size            =   9.75
  55.          Charset         =   0
  56.          Weight          =   400
  57.          Underline       =   0   'False
  58.          Italic          =   0   'False
  59.          Strikethrough   =   0   'False
  60.       EndProperty
  61.       Height          =   2175
  62.       Left            =   240
  63.       MultiLine       =   -1  'True
  64.       ScrollBars      =   3  'Both
  65.       TabIndex        =   8
  66.       Top             =   3720
  67.       Width           =   8895
  68.    End
  69.    Begin VB.CommandButton cmdHSplit 
  70.       Appearance      =   0  'Flat
  71.       BackColor       =   &H80000005&
  72.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  73.          Name            =   "Courier New"
  74.          Size            =   1.5
  75.          Charset         =   0
  76.          Weight          =   700
  77.          Underline       =   0   'False
  78.          Italic          =   0   'False
  79.          Strikethrough   =   0   'False
  80.       EndProperty
  81.       Height          =   90
  82.       Left            =   120
  83.       TabIndex        =   11
  84.       Top             =   2880
  85.       Width           =   9750
  86.    End
  87.    Begin VB.CommandButton cmdVSplit 
  88.       Appearance      =   0  'Flat
  89.       BackColor       =   &H80000005&
  90.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  91.          Name            =   "MS Sans Serif"
  92.          Size            =   8.25
  93.          Charset         =   0
  94.          Weight          =   700
  95.          Underline       =   0   'False
  96.          Italic          =   0   'False
  97.          Strikethrough   =   0   'False
  98.       EndProperty
  99.       Height          =   2415
  100.       Left            =   2040
  101.       TabIndex        =   10
  102.       Top             =   720
  103.       Width           =   90
  104.    End
  105.    Begin VB.ListBox listMessages 
  106.       Appearance      =   0  'Flat
  107.       Height          =   1230
  108.       Left            =   5640
  109.       TabIndex        =   7
  110.       Top             =   885
  111.       Width           =   3615
  112.    End
  113.    Begin VB.ListBox listFolders 
  114.       Appearance      =   0  'Flat
  115.       Height          =   1470
  116.       Left            =   0
  117.       TabIndex        =   6
  118.       Top             =   1080
  119.       Width           =   4155
  120.    End
  121.    Begin VB.CheckBox Flag 
  122.       Appearance      =   0  'Flat
  123.       BackColor       =   &H80000005&
  124.       Caption         =   "Flag"
  125.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  126.          Name            =   "MS Sans Serif"
  127.          Size            =   8.25
  128.          Charset         =   0
  129.          Weight          =   700
  130.          Underline       =   0   'False
  131.          Italic          =   0   'False
  132.          Strikethrough   =   0   'False
  133.       EndProperty
  134.       ForeColor       =   &H80000008&
  135.       Height          =   285
  136.       Left            =   9720
  137.       TabIndex        =   9
  138.       Top             =   360
  139.       Visible         =   0   'False
  140.       Width           =   690
  141.    End
  142.    Begin VB.CheckBox chkTrace 
  143.       Caption         =   "T&race"
  144.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  145.          Name            =   "MS Sans Serif"
  146.          Size            =   8.25
  147.          Charset         =   0
  148.          Weight          =   400
  149.          Underline       =   0   'False
  150.          Italic          =   0   'False
  151.          Strikethrough   =   0   'False
  152.       EndProperty
  153.       Height          =   240
  154.       Left            =   5730
  155.       TabIndex        =   4
  156.       Top             =   345
  157.       Value           =   1  'Checked
  158.       Width           =   1110
  159.    End
  160.    Begin VB.CheckBox chkBlocking 
  161.       Caption         =   "&Blocking"
  162.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  163.          Name            =   "MS Sans Serif"
  164.          Size            =   8.25
  165.          Charset         =   0
  166.          Weight          =   400
  167.          Underline       =   0   'False
  168.          Italic          =   0   'False
  169.          Strikethrough   =   0   'False
  170.       EndProperty
  171.       Height          =   240
  172.       Left            =   5730
  173.       TabIndex        =   3
  174.       Top             =   120
  175.       Value           =   1  'Checked
  176.       Width           =   1065
  177.    End
  178.    Begin VB.CommandButton cmdReply 
  179.       Appearance      =   0  'Flat
  180.       BackColor       =   &H80000005&
  181.       Caption         =   "&Reply"
  182.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  183.          Name            =   "MS Sans Serif"
  184.          Size            =   8.25
  185.          Charset         =   0
  186.          Weight          =   400
  187.          Underline       =   0   'False
  188.          Italic          =   0   'False
  189.          Strikethrough   =   0   'False
  190.       EndProperty
  191.       Height          =   375
  192.       Left            =   2280
  193.       TabIndex        =   2
  194.       Top             =   120
  195.       Width           =   1020
  196.    End
  197.    Begin VB.CommandButton cmdSendMessage 
  198.       Appearance      =   0  'Flat
  199.       BackColor       =   &H80000005&
  200.       Caption         =   "&Send"
  201.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  202.          Name            =   "MS Sans Serif"
  203.          Size            =   8.25
  204.          Charset         =   0
  205.          Weight          =   400
  206.          Underline       =   0   'False
  207.          Italic          =   0   'False
  208.          Strikethrough   =   0   'False
  209.       EndProperty
  210.       Height          =   375
  211.       Left            =   1200
  212.       TabIndex        =   1
  213.       Top             =   120
  214.       Width           =   1020
  215.    End
  216.    Begin VB.CommandButton cmdGetMail 
  217.       Appearance      =   0  'Flat
  218.       BackColor       =   &H80000005&
  219.       Caption         =   "&GetMail"
  220.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  221.          Name            =   "MS Sans Serif"
  222.          Size            =   8.25
  223.          Charset         =   0
  224.          Weight          =   400
  225.          Underline       =   0   'False
  226.          Italic          =   0   'False
  227.          Strikethrough   =   0   'False
  228.       EndProperty
  229.       Height          =   375
  230.       Left            =   120
  231.       TabIndex        =   0
  232.       Top             =   120
  233.       Width           =   1020
  234.    End
  235.    Begin MailLib.mMail Mail1 
  236.       Left            =   4560
  237.       Top             =   1200
  238.       _Version        =   327680
  239.       _ExtentX        =   847
  240.       _ExtentY        =   847
  241.       _StockProps     =   0
  242.       Blocking        =   0   'False
  243.       Debug           =   1
  244.       Host            =   ""
  245.       Timeout         =   0
  246.       ConnectType     =   1
  247.       PopPort         =   110
  248.       SmtpPort        =   25
  249.    End
  250.    Begin VB.Label lblPercentage 
  251.       Height          =   375
  252.       Left            =   3600
  253.       TabIndex        =   12
  254.       Top             =   120
  255.       Width           =   735
  256.    End
  257.    Begin VB.Line Line2 
  258.       BorderColor     =   &H00808080&
  259.       X1              =   -75
  260.       X2              =   7245
  261.       Y1              =   690
  262.       Y2              =   690
  263.    End
  264.    Begin VB.Line Line1 
  265.       BorderColor     =   &H00FFFFFF&
  266.       X1              =   60
  267.       X2              =   7275
  268.       Y1              =   15
  269.       Y2              =   15
  270.    End
  271.    Begin VB.Menu FileMenu 
  272.       Caption         =   "&File"
  273.       Begin VB.Menu FileExit 
  274.          Caption         =   "E&xit"
  275.       End
  276.    End
  277.    Begin VB.Menu SettingsMenu 
  278.       Caption         =   "Se&ttings"
  279.       Begin VB.Menu SettingsUser 
  280.          Caption         =   "&User..."
  281.       End
  282.       Begin VB.Menu SettingsConnection 
  283.          Caption         =   "&Connection..."
  284.       End
  285.    End
  286.    Begin VB.Menu ShowMenu 
  287.       Caption         =   "Sh&ow"
  288.       Begin VB.Menu ShowHeaders 
  289.          Caption         =   "&Headers"
  290.       End
  291.       Begin VB.Menu ShowSourceMenu 
  292.          Caption         =   "&Source"
  293.       End
  294.    End
  295. Attribute VB_Name = "MailForm"
  296. Attribute VB_Creatable = False
  297. Attribute VB_Exposed = False
  298. ' Sample program for Mabry Mail Control
  299. ' This sample shows both blocking and non-blocking use of
  300. ' the Mabry Mail control.  Please note that this sample does
  301. ' not trap errors returned by the control (connection failure,
  302. ' for instance).  If an error is returned you'll see the usual VB
  303. ' error message box.
  304. ' Zane Thomas/Sept 96
  305. Option Explicit
  306. ' state is used to determine what to do
  307. ' when the Done and DataReady events are fired
  308. Dim State As Integer
  309. Const StateDisconnected = 0
  310. Const StateGettingEMail = 1
  311. Const StateSelectGroup = 2
  312. Const StateGetArticleIDs = 3
  313. Const StateGetArticle = 4
  314. Const StateGetHeader = 5
  315. Const StateXOver = 6
  316. Const StateConnecting = 7
  317. Const StateConnected = 8
  318. Const StateDisconnecting = 9
  319. Const StateDeleting = 10
  320. Const StateAborting = 11
  321. Dim NextCommand As Integer
  322. ' For spacing during Form_Resize
  323. Const Margin = 2
  324. Dim vbCrLf As String
  325. Dim MailDir As String
  326. Dim InboxDir As String
  327. Dim CurrentFolder As String
  328. Dim GettingMessage As Integer
  329. ' enough room for 20 folders
  330. Dim DirInfo(20) As DirCounters
  331. Private Sub Addline(S As String)
  332.     textBody.Text = textBody.Text & S & vbCrLf
  333. End Sub
  334. Private Sub chkBlocking_Click()
  335.     If (chkBlocking.Value) Then
  336.         Mail1.Blocking = True
  337.     Else
  338.         Mail1.Blocking = False
  339.     End If
  340. End Sub
  341. Private Sub chkHostDelete_Click()
  342.     If (chkHostDelete.Value = 1) Then
  343.         MsgBox "Messages will be deleted after they are read from the host.", 48
  344.     End If
  345. End Sub
  346. Private Sub cmdConnect_Click()
  347. End Sub
  348. Private Sub chkTrace_Click()
  349.     If (chkTrace.Value = 1) Then
  350.         Mail1.Debug = 1
  351.     Else
  352.         Mail1.Debug = 0
  353.     End If
  354. End Sub
  355. Private Sub cmdGetMail_Click()
  356.     State = StateConnecting
  357.     Mail1.Host = g_PopHost
  358.     Mail1.LogonName = g_PopUserName
  359.     Mail1.LogonPassword = g_PopPassword
  360.     Mail1.Action = MailActionConnect
  361.     If (Mail1.Blocking = True) Then
  362.         Mail1_Done
  363.     End If
  364. End Sub
  365. Private Sub cmdReply_Click()
  366.     NewMessage.txtTo = Mail1.From
  367.     NewMessage.Show
  368. End Sub
  369. Private Sub cmdSendMessage_Click()
  370.     NewMessage.Show
  371. End Sub
  372. Private Sub DisplayAttachmentMarker(Part As Integer)
  373.     Dim pos As Integer
  374.     Dim S   As String
  375.     Addline "----- Attachment " & Format(Part) & " -----"
  376.     Addline "Content: " & Mail1.ContentType & "\" & Mail1.ContentSubtype & " Double-click this line to display"
  377.     pos = 0
  378.     If (Len(Mail1.ContentDisposition) > 0) Then
  379.         pos = InStr(Mail1.ContentDisposition, "name=")
  380.         If (pos <> 0) Then
  381.             S = Mid(Mail1.ContentDisposition, pos + 5)
  382.         End If
  383.     End If
  384.     If (pos = 0) Then
  385.         If (Len(Mail1.ContentSubtypeParameters) > 0) Then
  386.             pos = InStr(Mail1.ContentSubtypeParameters, "name=")
  387.             If (pos <> 0) Then
  388.                 S = Mid(Mail1.ContentSubtypeParameters, pos + 5)
  389.             End If
  390.         End If
  391.     End If
  392.     If (S <> "") Then
  393.         Addline "filename: " & S
  394.     End If
  395.     Addline "------------------------"
  396. End Sub
  397. Private Sub DisplayBody()
  398.     Dim I As Integer
  399.     Dim enc As String
  400.     enc = Mail1.ContentTransferEncoding
  401.     If (enc = "base64" Or enc = "quoted-printable" Or enc = "mac-binhex40" Or enc = "x-uuencode") Then
  402.         '
  403.         ' Decode body and put it back in body.
  404.         '
  405.         ' NOTE: Once the body is changed you'd best not try
  406.         ' to decode it again.  Here the Buffer is used as the
  407.         ' destination for the decoded data.
  408.         '
  409.         Mail1.Flags = MailSrcIsBody Or MailDstIsBuffer
  410.         Mail1.Action = MailActionDecode
  411.         Addline CStr(Mail1.Buffer)
  412.     Else
  413.         For I = 0 To Mail1.BodyCount - 1
  414.             Addline CStr(Mail1.Body(I))
  415.         Next
  416.     End If
  417. End Sub
  418. Private Sub DisplayMessage()
  419.     Dim dwrtn As Long
  420.     '
  421.     ' Empty text box, suspend redraws, load message into textbox
  422.     '
  423.     textBody.Text = ""
  424.     dwrtn = SendMessage(textBody.hWnd, WM_SETREDRAW, 0, 0&)
  425.     DisplayMessageText
  426.     textBody.SelLength = 0
  427.     dwrtn = SendMessage(textBody.hWnd, WM_SETREDRAW, -1, 0&)
  428. End Sub
  429. Private Sub DisplayMessageText()
  430.     Dim Part As Integer
  431.     Dim ctype As String
  432.     Dim csubtype As String
  433.     ctype = LCase$(Mail1.ContentType)
  434.     csubtype = LCase$(Mail1.ContentSubtype)
  435.     '
  436.     ' Display header if required
  437.     '
  438.     If (ShowHeaders.Checked) Then
  439.         Addline CStr(Mail1.HeaderText)
  440.     End If
  441.     '
  442.     ' If there's only one part then just display it
  443.     '
  444.     If (Mail1.Parts = 0) Then
  445.         If ((ctype = "text" And csubtype = "plain")) Then ' Or (ctype = "message" And csubtype = "rfc822")) Then
  446.             DisplayBody
  447.         Else
  448.             DisplayAttachmentMarker (Part)
  449.         End If
  450.     Else
  451.         '
  452.         ' Multiple parts, first part is displayed if it can
  453.         ' be otherwise it's displayed as an attachment.
  454.         ' All other parts are displayed as attachments.
  455.         '
  456.         For Part = 0 To Mail1.Parts - 1
  457.             Mail1.Part = Part
  458.             Mail1.Action = MailActionDescend
  459.             ctype = LCase$(Mail1.ContentType)
  460.             csubtype = LCase$(Mail1.ContentSubtype)
  461.             If ((ctype = "text" And csubtype = "plain")) Then ' Or (ctype = "message" And csubtype = "rfc822")) Then
  462.                 DisplayBody
  463.             Else
  464.                 DisplayAttachmentMarker (Part)
  465.             End If
  466.             Mail1.Action = MailActionAscend
  467.         Next
  468.     End If
  469. End Sub
  470. Private Sub FileExit_Click()
  471.     End
  472. End Sub
  473. Private Sub Form_Load()
  474.     Dim DirName As String
  475.     Dim dwrtn As Long
  476.     Static stops(3) As Long
  477.     '
  478.     ' Before you can use this program you must modify the
  479.     ' following two lines of code so that they point to
  480.     ' some existing valid directories on your system
  481.     '
  482.     ' You must also change the values below (for the
  483.     ' user name, hosts, etc.).
  484.     '
  485.     ' Be sure to comment out the message box when
  486.     ' you are done making the modifications.
  487.     '
  488.     ' MailDir = "c:\Email\"
  489.     ' InboxDir = "c:\Email\InBox\"
  490.     '
  491.     If (MailDir = "" Or InboxDir = "") Then
  492.         MsgBox "You must make modifications to the source code prior to running this sample.  Break into the debugger now and read the comments before and after this message box."
  493.     End If
  494.     If Right(MailDir, 1) <> "\" Then
  495.         MailDir = MailDir & "\"
  496.     End If
  497.     If Right(InboxDir, 1) <> "\" Then
  498.         InboxDir = InboxDir & "\"
  499.     End If
  500.     '
  501.     ' your user-friendly name goes here
  502.     '
  503.     g_username = "Your Name"
  504.     '
  505.     ' your smtp host's name or ip address
  506.     '
  507.     g_SmtpHost = "mailhost.yourhost.com"
  508.     '
  509.     ' your pop3 host's name or ip address
  510.     '
  511.     g_PopHost = "pophost.yourhost.com"
  512.     '
  513.     ' your e-mail address
  514.     '
  515.     g_emailaddr = "you@yourhost.com"
  516.     '
  517.     ' your pop3 login name and password
  518.     '
  519.     g_PopUserName = "you"
  520.     g_PopPassword = "yourpassword"
  521.     If (Mail1.Blocking = True) Then
  522.         chkBlocking.Value = 1
  523.     Else
  524.         chkBlocking.Value = 0
  525.     End If
  526.     Me.Show
  527.     '
  528.     ' Set listbox tabs
  529.     '
  530.     stops(0) = 125
  531.     stops(1) = 275
  532.     stops(2) = 500
  533.     dwrtn = SendMessage(listMessages.hWnd, LB_SETTABSTOPS, 3, stops(0))
  534.     vbCrLf = Chr$(13) & Chr$(10)
  535.     dwrtn = SendMessage(textBody.hWnd, EM_SETREADONLY, True, 0)
  536.     '
  537.     ' Display user and connection info
  538.     '
  539.     SetPopupPos UserInfo
  540.     UserInfo.Show 1
  541.     SetPopupPos ConnectionOptionsForm
  542.     ConnectionOptionsForm.Show 1
  543.     '
  544.     ' Load list of folders, subdirs of Const MailDir
  545.     '
  546.     DirName = Dir(MailDir, 16)
  547.     Do While (DirName <> "")
  548.         If (Left(DirName, 1) <> ".") Then
  549.             DirName = UCase$(Left(DirName, 1)) & LCase$(Right(DirName, Len(DirName) - 1))
  550.             listFolders.AddItem DirName
  551.         End If
  552.         DirName = Dir
  553.     Loop
  554.     listFolders.ListIndex = 0
  555. End Sub
  556. Private Sub Form_Resize()
  557.    If Me.WindowState = 1 Then
  558.       Exit Sub
  559.       End If
  560.    Line1.X1 = 0
  561.    Line2.X1 = 0
  562.    Line1.X2 = Me.ScaleWidth
  563.    Line2.X2 = Me.ScaleWidth
  564.    cmdVSplit.Height = cmdHSplit.Top - Line2.Y2 - 1
  565.    cmdHSplit.Left = 0
  566.    cmdHSplit.Width = Me.ScaleWidth
  567.    listFolders.Top = Line2.Y1 + Margin
  568.    listFolders.Height = cmdHSplit.Top - Line2.Y1 - Margin * 2
  569.    listFolders.Left = Margin
  570.    listFolders.Width = cmdVSplit.Left - Margin * 2
  571.    listMessages.Top = Line2.Y1 + Margin
  572.    listMessages.Height = cmdHSplit.Top - Line2.Y1 - Margin * 2
  573.    listMessages.Left = cmdVSplit.Left + cmdVSplit.Width + Margin
  574.    listMessages.Width = Me.ScaleWidth - listMessages.Left - Margin
  575.    textBody.Top = cmdHSplit.Top + cmdHSplit.Height + Margin
  576.    textBody.Height = Me.ScaleHeight - (cmdHSplit.Top + cmdHSplit.Height) - Margin * 2
  577.    textBody.Left = Margin
  578.    textBody.Width = Me.ScaleWidth - Margin * 2
  579.    End Sub
  580. Private Function GetEditControlLine(hWnd As Long, lineno As Integer) As String
  581.    Dim dwrtn   As Long
  582.    Dim linelen As Long
  583.    Dim S       As String
  584.    Dim charno  As Long
  585.    ' Get first char on line
  586.    charno = SendMessage(hWnd, EM_LINEINDEX, lineno, 0&)
  587.    ' So we can get the length
  588.    linelen = SendMessage(hWnd, EM_LINELENGTH, charno, 0&)
  589.    ' Allocate buffer and initialize.  Length of buffer is
  590.    ' stored in first two bytes.
  591.    S = String$(linelen + 1, 0)
  592.    S = Chr((CInt(linelen) And &HFF00) \ 255) & S
  593.    S = Chr((CInt(linelen) And &HFF)) & S
  594.    ' Read line from textbox
  595.    dwrtn = SendMessage(hWnd, EM_GETLINE, lineno, ByVal S)
  596.    GetEditControlLine = S
  597.    End Function
  598. Private Function GetNewFilename(DirName As String) As String
  599.    Dim I As Integer
  600.    For I = 0 To UBound(DirInfo)
  601.       If (UCase(DirInfo(I).DirName) = UCase(DirName)) Then
  602.             DirInfo(I).HighestMsg = DirInfo(I).HighestMsg + 1
  603.             GetNewFilename = Format(DirInfo(I).HighestMsg, "00000000.msg")
  604.             Exit Function
  605.          End If
  606.       Next I
  607.       
  608.       MsgBox "Ouch! Couldn't make new file in " & DirName
  609.       End
  610.    End Function
  611. Private Sub Label1_Click()
  612. End Sub
  613. Private Sub listFolders_Click()
  614.     Dim filename    As String
  615.     Dim filenames() As String
  616.     Dim stab        As String
  617.     Dim curnum      As Long
  618.     Dim highnum     As Long
  619.     Dim I           As Integer
  620.     ReDim Preserve filenames(0) As String
  621.     highnum = -1
  622.     '
  623.     ' Folder chosen, list messages.
  624.     '
  625.     stab = Chr$(9)
  626.     listMessages.Clear
  627.     CurrentFolder = listFolders.List(listFolders.ListIndex)
  628.     'NOTE-If you get an error on the below line, you need to create
  629.     'a valid inbox as described in the Form_Load procedure.
  630.     filename = Dir(MailDir & CurrentFolder & "\" & "*.msg", 0)
  631.     Do While (filename <> "")
  632.         filenames(UBound(filenames)) = filename
  633.         ReDim Preserve filenames(UBound(filenames) + 1) As String
  634.         filename = Dir
  635.     Loop
  636.     If UBound(filenames) <= 0 Then
  637.        UpdateCounter CurrentFolder, 0
  638.     Else
  639.        ReDim Preserve filenames(UBound(filenames) - 1) As String
  640.        SortStringArray filenames()
  641.        For I = 0 To UBound(filenames)
  642.            filename = filenames(I)
  643.            '
  644.            ' Read message
  645.            '
  646.            Mail1.SrcFilename = MailDir & CurrentFolder & "\" & listMessages.List(listMessages.ListIndex) & filename
  647.            Mail1.Flags = MailSrcIsFile
  648.            Mail1.Action = MailActionReadMessage
  649.            '
  650.            ' Display subject, from, data
  651.            '
  652.            listMessages.AddItem Mail1.Subject & stab & Mail1.From & stab & Mail1.Date
  653.            '
  654.            ' Filename is dddddddd.msg, stash dddddddd part in ItemData
  655.            '
  656.            curnum = Val(filename)
  657.            listMessages.ItemData(listMessages.NewIndex) = Val(filename)
  658.            If (highnum < curnum) Then
  659.                highnum = curnum
  660.            End If
  661.        Next
  662.        UpdateCounter CurrentFolder, highnum
  663.     End If
  664. End Sub
  665. Private Sub listMessages_Click()
  666.    Dim dwrtn As Long
  667.    ' Chose a message, make name from ItemData
  668.    Mail1.SrcFilename = MailDir & CurrentFolder & "\" & Format(listMessages.ItemData(listMessages.ListIndex), "00000000.msg")
  669.    ' Read and display
  670.    Mail1.Flags = MailSrcIsFile
  671.    Mail1.Action = MailActionReadMessage
  672.    DisplayMessage
  673.    End Sub
  674. Private Sub Mail1_AsyncError(ByVal ErrorCode As Integer, ByVal ErrorMsg As String)
  675.    MsgBox "AsyncError: " & ErrorMsg & "(" & Str(ErrorCode) & ")"
  676.    End Sub
  677. Private Sub MAIL1_Debug(ByVal message As String)
  678.    If (chkTrace.Value <> 0) Then
  679.       Debug.Print message
  680.       End If
  681.    End Sub
  682. Private Sub Mail1_Done()
  683.     Select Case State
  684.         Case StateConnecting
  685.             State = StateGettingEMail
  686.             If (Mail1.PopMessageCount <> 0) Then
  687.                 cmdGetMail.Enabled = False
  688.                 GettingMessage = 0
  689.                 NextCommand = MailActionReadMessage
  690.                 Timer1.Enabled = True
  691.             Else
  692.                 MsgBox "No mail waiting"
  693.                 State = StateDisconnecting
  694.                 Mail1.Action = MailActionDisconnect
  695.             End If
  696.         Case StateGettingEMail
  697.             '
  698.             ' Write received message to disk
  699.             '
  700.             Mail1.Flags = MailDstIsFile
  701.             Mail1.DstFilename = MailDir & CurrentFolder & "\" & GetNewFilename(CurrentFolder)
  702.             Mail1.Action = MailActionWriteMessage
  703.             '
  704.             ' Figure out what to do next
  705.             '
  706.             If (chkHostDelete.Value = 1) Then
  707.                 NextCommand = MailActionHostDelete
  708.             ElseIf (GettingMessage < Mail1.PopMessageCount) Then
  709.                 NextCommand = MailActionReadMessage
  710.             Else
  711.                 NextCommand = MailActionDisconnect
  712.             End If
  713.             Timer1.Enabled = True
  714.         Case StateDeleting
  715.             If (GettingMessage < Mail1.PopMessageCount) Then
  716.                 NextCommand = MailActionReadMessage
  717.             Else
  718.                 NextCommand = MailActionDisconnect
  719.             End If
  720.             Timer1.Enabled = True
  721.         Case StateDisconnecting
  722.             cmdGetMail.Enabled = True
  723.             State = StateDisconnected
  724.             listFolders_Click
  725.     End Select
  726. End Sub
  727. Private Sub SetPopupPos(foo As Form)
  728.    foo.Top = Me.Top + Me.Height / 5
  729.    foo.Left = Me.Left + (Me.Width - foo.Width) / 2
  730.    End Sub
  731. Private Sub Mail1_Progress(ByVal Numerator As Long, ByVal Denominator As Long)
  732.    If (Denominator <> 0) Then
  733.       lblPercentage.Caption = Format(Fix(Numerator / Denominator * 100)) & "%"
  734.    Else
  735.       lblPercentage.Caption = 0
  736.       End If
  737.    End Sub
  738. Private Sub SettingsConnection_Click()
  739.    SetPopupPos ConnectionOptionsForm
  740.    ConnectionOptionsForm.Show 1
  741.    End Sub
  742. Private Sub SettingsUser_Click()
  743.    SetPopupPos UserInfo
  744.    UserInfo.Show 1
  745.    End Sub
  746. Private Sub ShowHeaders_Click()
  747.    ShowHeaders.Checked = Not ShowHeaders.Checked
  748.    ' Skip errors here if Click when there is no
  749.    ' selected message
  750.    On Error Resume Next
  751.    DisplayMessage
  752.    If (Err <> 0 And Err <> 380) Then
  753.       MsgBox Error
  754.       End If
  755.    On Error GoTo 0
  756.    End Sub
  757. Private Sub ShowSourceMenu_Click()
  758.    Mail1.Flags = MailDstIsBuffer
  759.    Mail1.Action = MailActionWriteMessage
  760.    SourceDisplay.text1.Text = Mail1.Buffer
  761.    SourceDisplay.Show
  762.    End Sub
  763. Private Sub SortStringArray(aFiles() As String)
  764.     Dim Distance As Integer
  765.     Dim Size As Integer
  766.     Dim index As Integer
  767.     Dim NextElement As Integer
  768.     Dim Temp As String
  769.     Size = UBound(aFiles) - LBound(aFiles) + 1
  770.     Distance = 1
  771.     While (Distance <= Size)
  772.         Distance = 2 * Distance
  773.     Wend
  774.     Distance = (Distance / 2) - 1
  775.     While (Distance > 0)
  776.         NextElement = LBound(aFiles) + Distance
  777.         While (NextElement <= UBound(aFiles))
  778.             index = NextElement
  779.             Do
  780.                 If index >= (LBound(aFiles) + Distance) Then
  781.                     If aFiles(index) < aFiles(index - Distance) Then
  782.                         Temp = aFiles(index)
  783.                         aFiles(index) = aFiles(index - Distance)
  784.                         aFiles(index - Distance) = Temp
  785.                     Else
  786.                         Exit Do
  787.                     End If
  788.                 Else
  789.                     Exit Do
  790.                 End If
  791.             Loop
  792.             NextElement = NextElement + 1
  793.         Wend
  794.         Distance = (Distance - 1) / 2
  795.     Wend
  796. End Sub
  797. Private Sub textBody_Click()
  798. '   textBody.SelLength = 0
  799.    End Sub
  800. Private Sub textBody_DblClick()
  801.     Dim dwrtn   As Long
  802.     Dim lineno  As Long
  803.     Dim linelen As Long
  804.     Dim S       As String
  805.     Dim I       As Integer
  806.     textBody.SelLength = 0
  807.     lineno = SendMessage(textBody.hWnd, EM_LINEFROMCHAR, -1, 0&)
  808.     If (lineno = 0) Then
  809.         ' can't possibly be of interest
  810.         Exit Sub
  811.     End If
  812.     S = GetEditControlLine(CLng(textBody.hWnd), CInt(lineno))
  813.     '
  814.     ' shortcut out if not possibly significant
  815.     '
  816.     If (Len(S) < 20) Then
  817.         Exit Sub
  818.     End If
  819.     '
  820.     ' Ok, see if this is an attachment line
  821.     '
  822.     If (Left(S, 9) = "Content: " And InStr(S, "Double-click this line to display") <> 0) Then
  823.         '
  824.         ' Got an attachment, just put up message if can't be displayed
  825.         '
  826.         If (InStr(S, "text\plain") = 0 And InStr(S, "message") = 0 And InStr(S, "multipart") = 0) Then
  827.             MsgBox "This part requires special handling.  Might be a zip file, for instance."
  828.         Else
  829.             '
  830.             ' Get previous line, has ----- Attachment {n}n -----
  831.             '
  832.             S = GetEditControlLine(CLng(textBody.hWnd), CInt(lineno - 1))
  833.             '
  834.             ' sleazy trick, works for upto 99 attachments
  835.             '
  836.             Mail1.Part = Val(Right(S, 11))
  837.             Mail1.Action = MailActionDescend
  838.             textBody.Text = ""
  839.             DisplayMessage
  840.         End If
  841.     End If
  842. End Sub
  843. Private Sub textBody_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  844. '   textBody.SelLength = 0
  845.    End Sub
  846. Private Sub Timer1_Timer()
  847.     Static inhere As Integer
  848.     If (inhere <> 0) Then
  849.         Exit Sub
  850.     End If
  851.     inhere = 1
  852.     Timer1.Enabled = False
  853.     Select Case NextCommand
  854.         Case MailActionReadMessage
  855.             State = StateGettingEMail
  856.             GettingMessage = GettingMessage + 1
  857.             Mail1.MessageID = Format(GettingMessage)
  858.             Mail1.Flags = MailSrcIsHost
  859.             Mail1.Action = MailActionReadMessage
  860.         Case MailActionHostDelete
  861.             State = StateDeleting
  862.             Mail1.Action = MailActionHostDelete
  863.         Case MailActionDisconnect
  864.             State = StateDisconnecting
  865.             Mail1.Action = MailActionDisconnect
  866.         Case MailActionAbort
  867.             State = StateAborting
  868.             Mail1.Action = MailActionAbort
  869.     End Select
  870.     If (Mail1.Blocking = True) Then
  871.         Mail1_Done
  872.     End If
  873.     inhere = 0
  874. End Sub
  875. Private Sub UpdateCounter(DirName As String, Value As Long)
  876.    Dim I As Integer
  877.    For I = 0 To UBound(DirInfo)
  878.       If (DirInfo(I).DirName = "") Then
  879.          Exit For
  880.          End If
  881.       Next I
  882.       
  883.    If ((I = UBound(DirInfo)) And (DirInfo(I).DirName <> "")) Then
  884.       Exit Sub
  885.       End If
  886.    DirInfo(I).DirName = DirName
  887.    DirInfo(I).HighestMsg = Value
  888.    End Sub
  889.